package dibazhou;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

interface GeneralStack<T>{
	T push(T item);            
    T pop();                 
    T peek();                
    public boolean empty();
    public int size();
}
class ArrayListGeneralStack<T> implements GeneralStack<T>{
    private List<T> list;
	public ArrayListGeneralStack() {
		this.list = new ArrayList<T>();
	}
	@SuppressWarnings("unchecked")
	@Override
	public T push(Object item) {
		if (item == null) return null;
		list.add((T) item);
		return (T)item;
	}
	@Override
	public T pop() {
		if (list.isEmpty()) return null;
		T i = list.remove(list.size()-1);
		return i;
	}
	@Override
	public T peek() {
		if (list.isEmpty()) return null;
		T i = list.get(list.size()-1);
		return i;
	}
	@Override
	public boolean empty() {
		if(list.isEmpty()) return true;
		return false;
	}
	@Override
	public int size() {
		return list.size();
	}
	@Override
	public String toString() {
		return list.toString();
	}
	
}
class Car{
	private int id;
	private String name;
	public Car(int id, String name) {
		this.id = id;
		this.name = name;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Override
	public String toString() {
		return "Car [id=" + id + ", name=" + name + "]";
	}
	
}

public class Main3 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String str = sc.next();
			if (str.equals("quit")) break;
			if (str.equals("Integer"))
			{
				System.out.println("Integer Test");
				ArrayListGeneralStack<Integer> stack1=new ArrayListGeneralStack<Integer>();
				int m=sc.nextInt();
				int n=sc.nextInt();
				int sum1 = 0;
				for (int i = 0; i < m; i++) 
				{
					Integer number1 = sc.nextInt();
					System.out.println("push:"+stack1.push(number1));
					sum1 += number1;
				}
				for (int i = 0; i < n; i++) 
				{
					Integer popnum = (Integer) stack1.pop();
					System.out.println("pop:" + popnum);
					if(popnum != null) sum1-=popnum;
				}
				System.out.println(stack1);
				System.out.println("sum=" + sum1 );
				System.out.println(stack1.getClass().getInterfaces()[0]);
			}
			if (str.equals("Double"))
			{
				System.out.println("Double Test");
				int m1 = sc.nextInt();
				int n1 = sc.nextInt();
				Double sum2 = 0.0;
				ArrayListGeneralStack<Double> stack2=new ArrayListGeneralStack<Double>();	
				for (int i = 0; i < m1; i++) 
				{
					Double number2 = sc.nextDouble();
					System.out.println("push:" + stack2.push(number2));
					sum2 += number2;
				}
				for (int i = 0; i < n1; i++) 
				{
					Double popnum = (Double) stack2.pop();
					System.out.println("pop:" + popnum);
					if(popnum != null) sum2 -= popnum;
				}
				DecimalFormat df = new DecimalFormat("#.##");
				sum2 = Double.parseDouble(df.format(sum2));
				System.out.println(stack2);
				System.out.println("sum=" + sum2 );
				System.out.println(stack2.getClass().getInterfaces()[0]);
			}
			if (str.equals("Car")) {
				System.out.println("Car Test");
				ArrayListGeneralStack<Car> stack3 = 
						new ArrayListGeneralStack<Car>();
				int m2 = sc.nextInt();
				int n2 = sc.nextInt();
				for (int i = 0; i < m2; i++) {
					Car car = new Car(sc.nextInt(),sc.next());
					System.out.println("push:" + stack3.push(car));
				}
				for (int i = 0; i < n2; i++) {
					System.out.println("pop:" + stack3.pop());
				}
				System.out.println(stack3);
				while(!stack3.empty()){
					System.out.println(stack3.pop().getName());
				}
				System.out.println(stack3.getClass().getInterfaces()[0]);
			}
		}
		sc.close();

	}
}

